package org.teamh.connection.json;

import org.teamh.connection.json.command.JsonSender;
import org.teamh.connection.json.handler.JsonConnectionHandler;
import org.teamh.game.Start;

public class NOOP {
	
	private static Thread thread;
	private static boolean running;
	
	private NOOP() {}
	
	public static void start(final Start start) {
		if(running) {
			return;
		}
		
		thread = new Thread(new Runnable() {
			@Override
			public void run() {
				while (running && start.getConnection().getMessageReceiver() instanceof JsonConnectionHandler) {
					JsonSender.noop();
					
					try {
						Thread.sleep(30000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		});
	}
	
	public static void stop() {
		thread.interrupt();
		running = false;
	}
	
	public static boolean isRunning() {
		return running;
	}
}
